package cn.ldf.keepaccounts.controller;

import cn.hutool.core.codec.Base64Decoder;
import cn.hutool.core.text.StrPool;
import cn.ldf.keepaccounts.constant.BaseConstant;
import cn.ldf.keepaccounts.entity.dto.AvatarFileDTO;
import cn.ldf.keepaccounts.entity.pojo.UserFile;
import cn.ldf.keepaccounts.entity.pojo.Users;
import cn.ldf.keepaccounts.entity.vo.R;
import cn.ldf.keepaccounts.service.UserFileService;
import cn.ldf.keepaccounts.utils.ExceptionUtil;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 用户文件控制层
 * @author ldf
 * @code May there be no bugs in the world!
 */
@RestController
@RequestMapping("userFile")
public class UserFileController {

    @Resource
    private UserFileService userFileService;

    /**
     * 上传支付码
     *
     * @param avatarFileDTO 文件
     * @return 结果集
     */
    @PostMapping("uploadPaymentCode")
    public R<Boolean> uploadPaymentCode(@Valid @RequestBody AvatarFileDTO avatarFileDTO) {
        String contentType = avatarFileDTO.getContentType();
        ExceptionUtil.throwMsg(() -> !BaseConstant.IMAGES_TYPE.contains(contentType), "上传图片类型不符合要求");
        return R.success(this.userFileService.uploadPaymentCode(avatarFileDTO));
    }


    /**
     * 根据openIds获取支付码
     *
     * @param openIds openIds
     * @return 结果集
     */
    @GetMapping("getListPaymentCodeByOpenIds")
    public R<List<UserFile>> getListPaymentCodeByOpenIds(@RequestParam List<String> openIds) {
        return R.success(this.userFileService.getListPaymentCodeByOpenIds(openIds));
    }

}
